<h2 class="dialog_title"><span>Rata-rata Perolehan Point Seluruh Departemen</span></h2>
<div class="dialog_content" style="padding: 10px 20px; width:800px">
<table width="100%" border="0" cellpadding="5" cellspacing="0">
	<tr>
		<td>Periode : <strong><?php echo date("m-Y",$startPeriode) ?> - <?php echo date("m-Y",$endPeriode) ?></strong></td>
	</tr>
</table>
<table style="border:1px solid #457A3F;" width="100%" border="0" cellpadding="5" cellspacing="0">
  <tr class="header">
  	<th align="left"><span class="colorWhite">Kode Karyawan</span></th>
  	<th align="left"><span class="colorWhite">Nama Karyawan</span></th>
  	<th align="left"><span class="colorWhite">Periode</span></th>
    <th align="right"><span class="colorWhite">Jumlah Point</span></th>  
  </tr>
  <tbody id="searchKary-table" style="overflow:scroll; height:200px" >
<?php 
	$sql = "SELECT e.ID_DEPARTMENT, e.NAMA_DEPARTMENT, a.KODE_KARYAWAN, b.NAMA_KARYAWAN, DATE_FORMAT( a.PERB_TGL,  '%m-%Y' ) AS PERIODE, SUM( a.PERB_POINT ) AS POINT
			FROM perbuatan AS a, detil_perbuatan AS a1, data_karyawan AS b, relasi_div_jab_din AS c, dep_divisi_jabatan AS d, 
				data_department AS e, prestasipelanggaran AS f, detil_prestasi_pelanggaran AS g
			WHERE a.PERB_NO = a1.PERB_NO
				AND a1.DEPERB_STATUS =  '2'
				AND a.KODE_KARYAWAN = b.KODE_KARYAWAN
				AND b.KODE_KARYAWAN = c.KODE_KARYAWAN
				AND c.ID_DEP_DIV_JAB = d.ID_DEP_DIV_JAB
				AND d.ID_DEPARTMENT = e.ID_DEPARTMENT
				AND f.ACHIEV_ID = g.ACHIEV_ID
				AND g.DETACHIEV_ID = a1.DETACHIEV_ID
				AND DATE_FORMAT( a.PERB_TGL,  '%Y-%m' ) BETWEEN DATE_FORMAT(  '". date("Y-m-d",$startPeriode) ."',  '%Y-%m' )
					AND DATE_FORMAT(  '". date("Y-m-d",$endPeriode) ."',  '%Y-%m' ) 
			GROUP BY ID_DEPARTMENT, KODE_KARYAWAN, DATE_FORMAT( a.PERB_TGL,  '%Y-%m' ) 
			ORDER BY NAMA_DEPARTMENT, NAMA_KARYAWAN, PERIODE";
	$result = mysql_query($sql);
?>
<?php 
$pointCount = 0;
$deptName = array();
$deptKaryList = array();
?>
<?php while ($row = mysql_fetch_assoc($result)):?>
	<?php if (!in_array($row['KODE_KARYAWAN'],$deptKaryList)) $deptKaryList[] = $row['KODE_KARYAWAN']?>
	<?php if (!in_array($row['NAMA_DEPARTMENT'], $deptName)):?>
		<?php $deptName[] = $row['NAMA_DEPARTMENT']?>
    <tr bgcolor="#CCCCCC">
        <td colspan="4"><?php echo $row['NAMA_DEPARTMENT'] ?></td>
    </tr>
    <?php endif?>
    
    <tr <?php echo tag_zebra($z++)?>>
    	<td><?php echo $row['KODE_KARYAWAN']?></td>
    	<td><?php echo $row['NAMA_KARYAWAN']?></td>
    	<td><?php echo $row['PERIODE']?></td>
        <td align="right"><?php echo $row['POINT']? $row['POINT'] : 0?></td>
    </tr>
    <?php $pointCount += $row['POINT']?>
<?php endwhile;?>
<?php $jumlahKaryawan = count($deptKaryList)?>
  </tbody>
  <tr class="header">
    <th align="right" colspan="3"><span class="colorWhite">Total Point : </span></th>
    <th align="right"><span class="colorWhite"><?php echo $pointCount?></span></th>  
  </tr>
  <tr class="header">
    <th align="right" colspan="3"><span class="colorWhite">Jumlah Karyawan : </span></th>
    <th align="right"><span class="colorWhite"><?php echo $jumlahKaryawan?></span></th>  
  </tr>
  <tr class="header">
    <th align="right" colspan="3"><span class="colorWhite">Rata-rata Point Seluruh Departemen : </span></th>
    <th align="right"><span class="colorWhite"><?php echo $jumlahKaryawan? number_format($pointCount/$jumlahKaryawan,2):0 ?></span></th>  
  </tr>
</table>
</div>
<div class="dialog_buttons"><input type="button" value="Close" name="close" onclick="FBModal_hide()" /></div>